import { createRouter, createWebHashHistory } from 'vue-router'
import todolist from '@/components/todolist.vue'
import todolist_el from '@/components/todolist_el.vue'
import todolist_vant from '@/components/todolist_vant.vue'
import login2 from '@/components/login2.vue' // 引入登录组件
import submit2 from '@/components/submit2.vue'
import home from '@/components/home.vue'
import rewrite from '@/components/rewrite.vue'
import rewrite2 from '@/components/rewrite2.vue'
import autotodolist from '@/components/auto_todolist.vue'



const routes = [
  { path: '/', redirect: '/submit' }, // 设置重定向到注册页
  { path: '/login', component: login2 }, // 添加登录页路由
  { path: '/todolist', component: todolist },
  { path: '/todolist_el', component: todolist_el },//使用了el_plus组件库的todolist
  { path: '/todolist_vant', component: todolist_vant },//使用了vant组件库的todolist
  { path: '/submit', component: submit2 },
  { path: '/home', component: home },
  { path: '/rewrite', component: rewrite },
  { path: '/rewrite2', component: rewrite2 },
  { path: '/autotodolist', component: autotodolist },
]
const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 全局前置守卫
// router.beforeEach((to, from, next) => {
//   const isLoggedIn = false; // 模拟未登录状态
//   if (to.path !== '/login' && !isLoggedIn) {
//     next('/login'); // 未登录且访问非登录页，则跳转至登录页
//   } else {
//     next(); // 否则放行
//   }
// });

export default router